package cn.jluzh.blog.modules.user.controller;


import cn.jluzh.blog.commons.result.Result;
import cn.jluzh.blog.commons.result.ResultFactory;
import cn.jluzh.blog.modules.log.aspect.annotation.AutoLog;
import cn.jluzh.blog.modules.user.service.impl.UploadServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author hzhii
 */
@RestController
@Slf4j
@Api(tags = "上传相关接口")
@RequestMapping("upload")
public class UploadController {

    @Autowired
    UploadServiceImpl uploadService;

    @ApiOperation("上传头像")
    @PostMapping(value = "/avatar")
    @AutoLog("上传头像")
    public Result updateAvatar(
            @RequestParam MultipartFile avatar,
            @RequestHeader("Oauth-Token")String token
            ){
        return ResultFactory.buildSuccessResult(uploadService.updateAvatar(avatar));
    }


    @PostMapping("/picture")
    @AutoLog("上传图片")
    public Result upload(MultipartFile image) {
        return ResultFactory.buildSuccessResult(uploadService.updateImage(image));
    }
}

